package com.neusoft.neuiotms.dcom.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotBlank;

import org.hibernate.validator.constraints.Length;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.neusoft.bizcore.web.jpa.model.AbstractAuditModel;
import com.neusoft.bizcore.web.jpa.model.Comment;
import com.neusoft.neuiotms.dcom.model.enums.MaintainTaskResultStatus;
import com.neusoft.neuiotms.dcom.model.enums.MaintainTaskSourceEnum;
import com.neusoft.neuiotms.dcom.model.enums.MaintainTaskStatusEnum;
import com.neusoft.neuiotms.dcom.model.enums.StopServiceNoticeSendStatusEnum;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@Entity
@Table(name = "neuiot_maintain_task")
@org.hibernate.annotations.Table(appliesTo = "neuiot_maintain_task", comment = "维护任务表")
public class MaintainTask extends AbstractAuditModel {

    private static final long serialVersionUID = 1L;

    @Length(max = 50, message = "任务编码不能超过{max}位")
    @Column(length = 50, nullable = false)
    @Comment("varchar(50) NOT NULL COMMENT '任务编码'")
    private String code;

    @NotBlank(message = "任务名称")
    @Length(max = 100, message = "名称不能超过{max}位")
    @Column(length = 100, nullable = false)
    @Comment("varchar(100) NOT NULL COMMENT '任务名称'")
    private String name;

    @ManyToOne
    private MaintainRule rule;

    @ManyToOne
    private MaintainPlan Plan;

    @NotBlank(message = "部门编码")
    @Length(max = 50, message = "部门编码不能超过{max}位")
    @Column(length = 50, nullable = false)
    @Comment("varchar(50) NOT NULL COMMENT '部门编码'")
    private String orgCode;

    @Length(max = 100, message = "部门名称不能超过{max}位")
    @Column(length = 100, nullable = true)
    @Comment("varchar(100) NULL COMMENT '部门名称'")
    private String orgName;

    @Length(max = 100, message = "维护类别Code不能超过{max}位")
    @Column(length = 100, nullable = false)
    @Comment("varchar(100) NULL COMMENT '维护类别Code'")
    private String modelCode;

    @Length(max = 100, message = "维护类别名称不能超过{max}位")
    @Column(length = 100, nullable = true)
    @Comment("varchar(100) NULL COMMENT '维护类别名称'")
    private String modelName;

    @Length(max = 50, message = "维护对象Code不能超过{max}位")
    @Column(length = 50, nullable = false)
    @Comment("varchar(50) NULL COMMENT '维护对象Code'")
    private String objCode;

    @Length(max = 100, message = "维护对象名称不能超过{max}位")
    @Column(length = 100, nullable = true)
    @Comment("varchar(100) NULL COMMENT '维护对象名称'")
    private String objName;

    @Comment("BIGINT NOT NULL COMMENT '执行人ID'")
    @Column(length = 50, nullable = false)
    private Long chargeUserId;

    @Length(max = 100, message = "执行人username名称不能超过{max}位")
    @Column(length = 100, nullable = false)
    @Comment("varchar(100) NULL COMMENT '执行人username'")
    private String chargeUserCode;

    @Length(max = 100, message = "执行人Name不能超过{max}位")
    @Column(length = 100, nullable = false)
    @Comment("varchar(100) NOT NULL COMMENT '执行人Name名称'")
    private String chargeUserName;

    @Enumerated(EnumType.STRING)
    @Column(length = 25, nullable = false)
    @Comment("varchar(25) NOT NULL COMMENT '任务状态'")
    private MaintainTaskStatusEnum status = MaintainTaskStatusEnum.undo;

    @Comment("bit(1) COMMENT '是否停止服务'")
    private boolean suspendService = false;

    @Comment(" COMMENT '量化时间(小时)'")
    private int quantifyingTime;

    @Column(nullable = true)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Comment("DATETIME DEFAULT NULL COMMENT '开始时间'")
    private Date startDateTime;

    @Column(nullable = true)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Comment("DATETIME DEFAULT NULL COMMENT '结束时间'")
    private Date endDateTime;

    @Enumerated(EnumType.STRING)
    @Column(length = 25, nullable = true)
    @Comment("varchar(25) NULL COMMENT '任务结果'")
    private MaintainTaskResultStatus result;

    @Length(max = 255, message = "参与人")
    @Column(length = 255, nullable = true)
    @Comment("varchar(255) NULL COMMENT '参与人'")
    private String joinUser;

    @Length(max = 30, message = "联系电话不能超过{max}位")
    @Column(length = 30, nullable = true)
    @Comment("varchar(30) NULL COMMENT '联系电话'")
    private String tel;

    @Enumerated(EnumType.STRING)
    @Column(length = 25, nullable = true)
    @Comment("varchar(25) NULL COMMENT '通知结果发送状态'")
    private StopServiceNoticeSendStatusEnum noticeSendStatus;

    @Lob
    @Column(columnDefinition = "longtext")
    @Comment("text COMMENT '结果描述")
    private String resultDesc;

    @Lob
    @Column(columnDefinition = "longtext")
    @Comment("text COMMENT '过程描述")
    private String processDesc;

    @Length(max = 255, message = "备注")
    @Column(length = 255, nullable = true)
    @Comment("varchar(255) NULL COMMENT '备注'")
    private String remarks;

    @Comment("bit(1) COMMENT '临时任务是否生成规则'")
    private boolean createRule = false;

    @Enumerated(EnumType.STRING)
    @Column(length = 25, nullable = false)
    @Comment("varchar(25) NULL COMMENT '任务来源'")
    private MaintainTaskSourceEnum source = MaintainTaskSourceEnum.period;

    @Lob
    @Column(columnDefinition = "longtext")
    @Comment("text COMMENT '对象编码集合'")
    private String jsonObjs;

    @Comment("BIGINT NOT NULL COMMENT '版本'")
    private Long version = 1L;
}
